/*
* @Author: yyf
* @Date: 2018/4/10
* @description: 投资事件 添加页 基本信息
*/
<template>
    <div>
        <el-row class="custom-title m-t-20 m-b-20">
            <h3>投融资基本信息
                <span class="m-l-20">最后更新时间：{{eventBasicInfo.modifyTime | cmsMoment}}</span>
                <el-button type="primary" class="m-l-20" @click="saveBasicInfo()" round>保存</el-button>
            </h3>
        </el-row>
        <el-form label-width="90px" class="custom-box p-20" :model="eventBasicInfo" :rules="rules" ref="basicForm">
            <el-row>
                <el-col :span="12">
                    <el-row>
                        <el-form-item label="中文标题" prop="title">
                            <el-autocomplete
                                class="w-100"
                                :maxlength="200"
                                v-model="eventBasicInfo.title"
                                :fetch-suggestions="getSearchTitle"
                                placeholder="请输入内容"
                                :trigger-on-focus="false"
                                @select="handleSelect">
                            </el-autocomplete>
                        </el-form-item>
                    </el-row>
                    <el-row>
                        <el-col :span="12">
                            <el-form-item label="开始时间" prop="startTime">
                                <el-date-picker
                                class="w-100"
                                v-model="eventBasicInfo.startTime"
                                type="date"
                                placeholder="选择日期">
                                </el-date-picker>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="结束时间" label-width="80px" prop="endTime">
                                <el-date-picker
                                    :disabled="!isEndTimeRequired"
                                    class="w-100"
                                    v-model="eventBasicInfo.endTime"
                                    type="date"
                                    placeholder="选择日期">
                                </el-date-picker>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="11">
                            <el-form-item label="交易状态" prop="tradeStatus">
                                <el-select v-model="eventBasicInfo.tradeStatus" @change="changeTradeStatus" class="w-100">
                                    <el-option 
                                        v-for="item in tradeStatus" 
                                        :key="item.dictValue" 
                                        :value="item.dictValue-0" 
                                        :label="item.dictName">
                                    </el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="13">
                            <el-form-item label="是否跨境交易" label-width="90px" prop="borderStatus" class="line-h-20">
                                <el-select v-model="eventBasicInfo.borderStatus" class="w-100">
                                    <el-option 
                                        v-for="item in whether" 
                                        :key="item.dictValue" 
                                        :value="item.dictValue-0" 
                                        :label="item.dictName">
                                    </el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="18">
                            <el-form-item label="标的企业" prop="companyName">
                                <el-tooltip :content="companyText" placement="top">
                                    <el-button v-model="eventBasicInfo.companyName" class="company-detail" @click="openCompanyDetailDialog">{{companyText}}</el-button>
                                </el-tooltip>
                            </el-form-item>
                        </el-col>
                        <el-col :span="4">
                            <el-form-item label-width="10px">
                                <el-button type="primary" @click="toCompanyDetail">查看详情</el-button>
                            </el-form-item>
                        </el-col>
                        <CompanyInfoDialog :companyDetailDialog="companyDetailDialog"
                                            @closeCompanyDialog="closeCompanyDialog"
                                            @getName="getName">
                        </CompanyInfoDialog>
                    </el-row>
                    <el-row>
                        <el-col :span="11">
                            <el-form-item label="总实际金额">
                                <el-input v-model="eventBasicInfo.amountActual">
                                    <template slot="append">万</template>
                                </el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="13">
                            <el-form-item label="币种" label-width="100px">
                                <el-select v-model="eventBasicInfo.currencyType" class="w-100">
                                    <el-option 
                                        v-for="item in currencyType" 
                                        :key="item.dictValue" 
                                        :value="item.dictValue-0" 
                                        :label="item.dictName">
                                    </el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="11">
                            <el-form-item label="总估计金额">
                                <el-input v-model="eventBasicInfo.amountEstimate">
                                    <template slot="append">万</template>
                                </el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="13">
                            <el-form-item label="交易量级" label-width="100px">
                                <el-select v-model="eventBasicInfo.tradeMagnitude" class="w-100">
                                    <el-option 
                                        v-for="item in tradeMagnitude" 
                                        :key="item.dictValue" 
                                        :value="item.dictValue-0" 
                                        :label="item.dictName">
                                    </el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="11">
                            <el-form-item label="总实际股权" prop="totalStockRate">
                                <el-input v-model="eventBasicInfo.totalStockRate">
                                    <template slot="append">%</template>
                                </el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="13">
                            <el-form-item label="估值" label-width="70px">
                                <el-input v-model="eventBasicInfo.valuation" class="w-50"></el-input>
                                <el-button type="primary" class="pull-right" @click="calculate" style="margin-top: 2px;">计算</el-button>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="8">
                            <el-form-item label="轮次" label-width="50px">
                                <el-select v-model="otherRound" @change="handleSelectRound" class="w-100">
                                    <el-option 
                                        v-for="item in investRound" 
                                        :key="item.id" 
                                        :value="item.id" 
                                        :label="item.roundName">
                                    </el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="6" v-if="roundE.length">
                            <el-form-item label-width="10px">
                                <el-select v-model="afterRoundE" class="w-100">
                                    <el-option 
                                        v-for="item in roundE" 
                                        :key="item.id" 
                                        :value="item.id" 
                                        :label="item.roundName">
                                    </el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="10" class="pull-right align-right">
                            <el-form-item label="控制权是否转让" label-width="80px" class="line-h-20">
                                <el-select v-model="eventBasicInfo.attornStatus" class="w-100">
                                    <el-option 
                                        v-for="item in whether" 
                                        :key="item.dictValue" 
                                        :value="item.dictValue-0" 
                                        :label="item.dictName">
                                    </el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="11">
                            <el-form-item label="交易类型" prop="tradeType">
                                <el-select v-model="eventBasicInfo.tradeType" class="w-100">
                                    <el-option 
                                        v-for="item in tradeType" 
                                        :key="item.dictValue" 
                                        :value="item.dictValue-0" 
                                        :label="item.dictName">
                                    </el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="13">
                            <el-form-item label="交易方式" label-width="100px">
                                <el-select v-model="eventBasicInfo.tradeMode" class="w-100">
                                    <el-option 
                                        v-for="item in tradeMode" 
                                        :key="item.dictValue" 
                                        :value="item.dictValue-0" 
                                        :label="item.dictName">
                                    </el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="11">
                            <el-form-item label="是否关联交易" label-width="110px">
                                <el-select v-model="eventBasicInfo.tradeRelation" class="w-100">
                                    <el-option 
                                        v-for="item in whether" 
                                        :key="item.dictValue" 
                                        :value="item.dictValue-0" 
                                        :label="item.dictName">
                                    </el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="13">
                            <el-form-item label="支付方式" label-width="100px" prop="payMode">
                                <el-select v-model="eventBasicInfo.payMode" class="w-100">
                                    <el-option 
                                        v-for="item in payMode" 
                                        :key="item.dictValue" 
                                        :value="item.dictValue-0" 
                                        :label="item.dictName">
                                    </el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="11" class="line-h-20">
                            <el-form-item label="标的企业是否上市">
                                <el-select v-model="isComOnMarcket" class="w-100" disabled>
                                    <el-option 
                                        v-for="item in whether" 
                                        :key="item.dictValue" 
                                        :value="item.dictValue" 
                                        :label="item.dictName">
                                    </el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12" class="line-h-20" :offset="1">
                            <el-form-item label="构成重大资产重组" label-width="80px" prop="reorganization">
                                <el-select v-model="eventBasicInfo.reorganization" class="w-100">
                                    <el-option 
                                        v-for="item in whether" 
                                        :key="item.dictValue" 
                                        :value="item.dictValue-0" 
                                        :label="item.dictName">
                                    </el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="11">
                            <el-form-item label="转让股票价格（每股）" class="line-h-20" label-width="100px">
                                <el-input v-model="eventBasicInfo.amountPrice">
                                    <template slot="append">万</template>
                                </el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="13">
                            <el-form-item label="股票数量" label-width="100px">
                                <el-input v-model="eventBasicInfo.sharesCount"></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                </el-col>
                <el-col :span="11" :offset="1">
                    <el-row>
                        <el-form-item label="CV行业分类" label-width="130px">
                            <el-cascader
                                disabled
                                class="w-100"
                                v-model="cvIndustryValue"
                                :options="cvIndustryListCascader"
                                :filterable="true"
                                :clearable="true" />
                        </el-form-item>
                    </el-row>
                    <el-row>
                        <el-form-item label="国标分类" label-width="130px">
                            <el-cascader
                                disabled
                                class="w-100"
                                v-model="csIndustryValue"
                                :options="csIndustryListCascader"
                                :filterable="true"
                                :clearable="true" />
                        </el-form-item>
                    </el-row>
                    <el-row>
                        <el-form-item label="证监会分类" label-width="130px">
                            <el-cascader
                                disabled
                                class="w-100"
                                v-model="sfcIndustryValue"
                                :options="sfcIndustryListCascader"
                                :filterable="true"
                                :clearable="true" />
                        </el-form-item>
                    </el-row>
                    <el-row>
                        <el-form-item label="申银万国" label-width="130px">
                            <el-cascader
                                disabled
                                class="w-100"
                                v-model="snIndustryValue"
                                :options="snIndustryListCascader"
                                :filterable="true"
                                :clearable="true" />
                        </el-form-item>
                    </el-row>
                    <el-row>
                        <el-form-item label="标签" label-width="130px">
                            <el-row class="custom-box minheight">
                                <el-tag
                                    class="m-r-5"
                                    v-for="tag in comTags"
                                    :key="tag.tagId"
                                    :type="tag.tagsType">
                                    {{tag.tagName}}
                                </el-tag>
                            </el-row>
                        </el-form-item>
                        <el-form-item label="交易描述" label-width="130px" prop="description">
                            <el-input type="textarea" :rows="4" v-model="eventBasicInfo.description"></el-input>
                        </el-form-item>
                        <el-form-item label="备注" label-width="130px">
                            <el-input type="textarea" :rows="4" v-model="eventBasicInfo.remark"></el-input>
                        </el-form-item>
                        <el-form-item label="信息来源" label-width="130px" prop="infoFrom">
                            <el-row v-for="(item, index) in eventInfoDtos" :key="index">
                                <a :href="item.infoFromUrl" target="_blank" class="cmsInfoUrl">{{item.infoFrom}}</a>
                                <button type="button" class="custom-btn custom-btn-round m-l-10 m-r-10">
                                    <i v-if="index !== 0" class="fa fa-close" @click="deleteInfoFrom(index)"></i>
                                    <i v-if="index === 0" class="fa fa-plus" @click="addInfoFrom"></i> 
                                </button>
                                <el-button type="primary" @click="editInfoFrom(index)">编辑详情</el-button>
                            </el-row>
                        </el-form-item>
                        <el-dialog :visible="infoFromDialog" :show-close="false" title="信息来源">
                            <el-form label-width="130px" :model="eventInfoDto" ref="eventInfoFrom" :rules="infoFromRules">
                                <el-row>
                                    <el-col :span="16">
                                        <el-form-item label="信息发生时间" prop="happenTime">
                                            <el-date-picker v-model="eventInfoDto.happenTime" placeholder="其请选择日期"></el-date-picker>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="8">
                                        <el-form-item label="媒体类型" label-width="80px" prop="mediaType">
                                            <el-select v-model="eventInfoDto.mediaType">
                                                <el-option label="新闻" :value="1"></el-option>
                                                <el-option label="报告" :value="2"></el-option>
                                            </el-select>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-form-item label="信息来源媒体" prop="infoFrom">
                                    <el-input v-model="eventInfoDto.infoFrom"></el-input>
                                </el-form-item>
                                <el-form-item label="信息来源url" prop="infoFromUrl">
                                    <el-input v-model="eventInfoDto.infoFromUrl"></el-input>
                                </el-form-item>
                            </el-form>
                            <span slot="footer" class="dialog-footer">
                                <el-button type="primary" @click="addEventInfoFrom">确 定</el-button>
                                <el-button @click="cancelAddInfoFrom">取 消</el-button>
                            </span>
                        </el-dialog>
                    </el-row>
                </el-col>
            </el-row>
        </el-form>
    </div>
</template>
<script lang="ts">
import Vue from 'vue';
import { Component } from 'vue-property-decorator';
import { getCascaderData } from '../../../../libs/utils';
import { EventDto, EventInfoDto, EventTitleVO } from '../../../../api/Interface';
import { StateMessage } from '../../../../service/common/interface';
import EventService from '../../../../service/event/index';
import CompanyInfoDialog from '../../../../components/company-info/index.vue';
import CompanyService from '../../../../service/subject/company/basic-info/index';
interface TagVo {
    tagId: number;
    tagName: string;
    tagsType: string;
}

@Component({
    components: {
        CompanyInfoDialog, // 企业弹框
    }
})
export default class BasicInfo extends Vue {
    // 从字典中获取下拉框数据
    public tradeStatus = this.$store.state.user.dictionary.dicList.tradeStatus; // 交易状态
    public whether = this.$store.state.user.dictionary.dicList.whether; // 是/否
    public currencyType = this.$store.state.user.dictionary.dicList.currencyType; // 货币类型
    public tradeMagnitude = this.$store.state.user.dictionary.dicList.tradeMagnitude; // 交易量级
    public tradeType = this.$store.state.user.dictionary.dicList.tradeType; // 交易类型
    public tradeMode = this.$store.state.user.dictionary.dicList.tradeMode; // 交易方式
    public payMode = this.$store.state.user.dictionary.dicList.payMode; // 支付方式
    public investRound = this.$store.state.user.dictionary.roundList; // 轮次
    // 添加事件参数类型
    public eventBasicInfo: EventDto = {} as EventDto; 
    // 轮次
    public roundE: object[] = []; // E轮以后数据
    public afterRoundE: number | null = null; // E轮以后
    public otherRound: number = 0; // 其他轮次
    // cv行业
    public cvIndustryList = this.$store.state.user.dictionary.cvIndustryList;
    public cvIndustryListCascader = getCascaderData( {data: this.cvIndustryList} );
    public cvIndustryValue: string[] = [];
    // 国标
    public csIndustryList = this.$store.state.user.dictionary.csIndustryList;
    public csIndustryListCascader = getCascaderData( {data: this.csIndustryList} );
    public csIndustryValue: string[] = [];
    // 证监会
    public sfcIndustryList = this.$store.state.user.dictionary.sfcIndustryList;
    public sfcIndustryListCascader = getCascaderData( {data: this.sfcIndustryList} );
    public sfcIndustryValue: string[] = [];
    // 申银万国
    public snIndustryList = this.$store.state.user.dictionary.snIndustryList;
    public snIndustryListCascader = getCascaderData( {data: this.snIndustryList} );
    public snIndustryValue: string[] = [];
    // 企业详情弹出框
    public companyDetailDialog: boolean = false;
    // 信息来源弹出框
    public infoFromDialog: boolean = false;
    // 信息来源
    public eventInfoDto: EventInfoDto = {} as EventInfoDto; // 信息来源详情
    public eventInfoDtos: Array<EventInfoDto> = [{  // 信息来源列表
        eventId: 0,         //事件id
        infoFromUrl: '',         //信息来源媒体URL
        mediaType: 1,         //媒体类型 1新闻、2报告
        id: 0,         //null
        infoFrom: '',         //信息来源媒体
        happenTime: ''         //发生时间
    }]; 
    public infoVolistIndex: number = 0; // 信息来源index
    // 菜单栏主ID
    public eventId: string = '';
    // 标的企业ID
    public companyId: string = '';
    public companyText: string = '企业库';
    public isComOnMarcket: string = '';
    public comTags: Array<TagVo> = [];
    // 中文名称搜索列表
    public titleSearchList: object[] = [];
    public infoStatus: string = '0000';
    public isEndTimeRequired: boolean = false;
    // 表单验证
    public rules = {
        title: [
            { required: true, message: '请输入中文标题', trigger: 'blur' },
        ],
        startTime: [
            { required: true, message: '请选择开始时间', trigger: 'blur' },
        ],
        endTime: [
            { required: this.isEndTimeRequired, message: '请选择结束时间', trigger: 'blur' },
        ],
        companyName: [
            { required: true, message: '请选择标的企业', trigger: 'blur' },
        ],
        // totalStockRate: [
        //     { validate: //, message: '股权比例不能超过100%', trigger: ['change', 'blur'] },
        // ],
        tradeStatus: [
            { required: true, message: '请选择交易状态', trigger: ['change', 'blur'] },
        ],
        description: [
            { required: true, message: '请填写交易描述', trigger: 'blur' },
        ],
        borderStatus: [
            { required: true, message: '请选择是否跨境交易', trigger: ['change', 'blur'] },
        ],
        tradeType: [
            { required: true, message: '请选择交易类型', trigger: ['change', 'blur'] },
        ],
        payMode: [
            { required: true, message: '请选择支付方式', trigger: ['change', 'blur'] },
        ],
        reorganization: [
            { required: true, message: '请选择构成重大资产重组', trigger: ['change', 'blur'] },
        ],
        infoFrom: [
            { required: true, validator: this.validateInfoFrom, trigger: 'blur' },
        ],
    };
    // 信息来源验证
    public infoFromRules = {
        happenTime: [
            { required: true, message: '请选择信息发生时间', trigger: 'blur' },
        ],
        mediaType: [
            { required: true, message: '请选择信息媒体类型', trigger: ['change', 'blur'] },
        ],
        infoFrom: [
            { required: true, message: '请填写信息来源媒体', trigger: 'blur' },
        ],
        infoFromUrl: [
            { validator: this.infoFromUrlCheck, trigger: 'blur' },
        ],
    };

    // refs
    public $refs: {
        basicForm: HTMLFormElement;
        eventInfoFrom: HTMLFormElement; // 信息来源
    };

    // 声明周期钩子
    public mounted() {
        // console.log(this.$store.state.user.dictionary);
        this.eventId = this.$route.params.eventId;
        if (this.eventId !== '-1') {
            this.getBasicInfo();
        }
    }
    // 获取基本信息
    public async getBasicInfo() {
        const res = await EventService.getEventDetail(this.eventId);
        if (res.resCode === '0') {
            this.eventBasicInfo = res.data;
            this.eventInfoDtos = res.data.eventInfos.length ? res.data.eventInfos : this.eventInfoDtos;
            if (res.data.companyId) {
                this.companyId = res.data.companyId;
                this.companyText = res.data.companyName;
                this.infoStatus = res.data.infoStatus;
            }
            // 轮次回显
            this.investRound.map( item => {
                if (item.id === res.data.investRound) {
                    this.otherRound = item.id;
                } else if (item.id === 14) { // E轮以后
                    this.otherRound = 14;
                    this.afterRoundE = res.data.investRound;
                    this.roundE = item.children;
                }
            });
            // 获取标的企业信息
            this.getCompanyInfo();
            // 信息状态回显
            this.$emit('changeInfo', res.data.infoStatus);
        }
    }
    // 标的企业信息
    public async getCompanyInfo() {
        this.comTags = [];
        const res = await CompanyService.getCompanyById(Number(this.companyId));
        if (res.resCode === '0') {
            // 标的企业是否上市回显
            switch (res.data.comState) {
                case 1:  // 已上市
                case 2:  // 新三板
                    this.isComOnMarcket = '1';
                    break;
                case 3:  // 非上市
                    this.isComOnMarcket = '2';
                    break;
                default:
                    this.isComOnMarcket = '';
                    break;
            }
            // 回显行业
            const industryList = res.data.industryList; // 所有行业分类
            industryList.map( (item) => {
                switch (item.industryType) {
                    case 1:
                        this.cvIndustryValue = this.cvIndustryValue.concat(item.oneLevel, item.twoLevel, item.threeLevel);
                        break;
                    case 2:
                        this.csIndustryValue = this.csIndustryValue.concat(item.oneLevel, item.twoLevel, item.threeLevel);
                        break;
                    case 3:
                        this.sfcIndustryValue = this.sfcIndustryValue.concat(item.oneLevel, item.twoLevel, item.threeLevel);
                        break;
                    case 4:
                        this.snIndustryValue = this.snIndustryValue.concat(item.oneLevel, item.twoLevel, item.threeLevel);
                        break;
                    default:
                        break;
                }
            });
            // 回显标签
            if (res.data.tagList.length) {
                res.data.tagList.map(item => {
                    this.comTags.push({
                        tagId: item.tagId,
                        tagName: item.tagName,
                        tagsType: item.tagsType ? item.tagsType.toString() : item.tagsType
                    });
                });
            }
        }
    }
    // 模糊查询带出详情 
    public handleSelect(val: {id: number, value: string}) {
        this.eventId = val.id.toString();
        this.$router.push({name: 'transaction-detail', params: {eventId: this.eventId, tabIndex: '0'}});
        this.getBasicInfo();
        this.$emit('getEventId', this.eventId);
    }
    // 中文名称模糊查询
    public async getSearchTitle(queryString: string, cb: any) {
        const res = await EventService.getSearchTitle({title: this.eventBasicInfo.title, eventType: 17});
        if (res.resCode === '0') {
            this.titleSearchList = res.data;
            const result = this.titleSearchList.map((item: EventTitleVO) => {
                return { value: item.title, id: item.id };
            });
            cb(result);
        }
    }
    // 通过交易状态判断结束时间是否必填
    public changeTradeStatus(value: number) {
        if (value !== 3) {
            this.isEndTimeRequired = true;
        } else {
            this.isEndTimeRequired = false;
        }
    }
    // 保存基本信息
    public async saveBasicInfo(info: StateMessage) {
        if (!this.eventBasicInfo.amountActual && !this.eventBasicInfo.amountEstimate) { // 总实际金额 和 总估计金额必填一项
            this.$message.warning('总实际金额和总估计金额必填一项');
        } else {
            this.eventBasicInfo.investRound = this.afterRoundE ? this.afterRoundE : this.otherRound;
            this.eventBasicInfo.eventType = 17; // 事件分类  17 融资事件 16 新股发行
            if (info) {
                this.eventBasicInfo.infoStatus = info.infoStatus;
                this.eventBasicInfo.publishMessage = info.publishMessage;
            } else {
                this.eventBasicInfo.infoStatus = this.infoStatus;
            }
            this.$refs.basicForm.validate(async (valid: boolean) => {
                if (valid) {
                    if (this.eventId === '-1') {
                        this.addTranscationEvent();
                    } else {
                        this.editTranscationEvent();
                    }
                }
            });
        }
    }
    // 添加基本信息
    public async addTranscationEvent() {
        const { resCode, data } = await EventService.addSaveEvent(this.eventBasicInfo);
        if (resCode === '0') {
            this.$message.success('添加成功！');
            this.eventId = data.toString();
            this.$router.push({ name: 'transaction-edit', params: { eventId: this.eventId, tabIndex: '0'} });
            this.$emit('getEventId', this.eventId);
        }
    }
    // 修改基本信息
    public async editTranscationEvent() {
        const { resCode } = await EventService.updateEvent(this.eventBasicInfo);
        if (resCode === '0') {
            this.$message.success('修改成功！');
        }
    }
    // 计算估值
    public calculate() {
        if (!this.eventBasicInfo.amountActual) {
            this.$message.warning('请输入总实际金额！');
        } else if (!this.eventBasicInfo.totalStockRate) {
            this.$message.warning('请输入总实际股权！');
        } else if (this.eventBasicInfo.totalStockRate.toString() === '0' || this.eventBasicInfo.amountActual.toString() === '0') {
            this.$set(this.eventBasicInfo, 'valuation', 0);
        } else {
            const valuation = this.eventBasicInfo.amountActual / this.eventBasicInfo.totalStockRate;
            this.$set(this.eventBasicInfo, 'valuation', valuation.toFixed(0));
        }
    }
    // 选择轮次
    public handleSelectRound(id: number) {
        if (id === 14) {
            this.investRound.map( item => {
                if (item.id === 14) {
                    this.roundE = item.children;
                } 
            });
        } else {
            this.roundE = [];
            this.afterRoundE = null;
        }
    }
    // 信息来源URL合法验证
    public infoFromUrlCheck(rule: any, value: string, callback: any) {
        const reg = /(http|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?/;
        if (!value || value === '') {
            callback(new Error('请输入信息来源媒体URL'));
        } else if (!reg.test(value.toLowerCase())) {
            callback(new Error('请输入合法的URL'));
        } else {
            callback();
        }
    }
    // 编辑详情
    public editInfoFrom(index: number) {
        this.infoFromDialog = true;
        this.eventInfoDto = {...this.eventInfoDtos[index]};
        this.infoVolistIndex = index;
    }
    // + 添加信息来源
    public addInfoFrom() {
        this.eventInfoDto = {mediaType: 1} as EventInfoDto;
        this.eventInfoDtos.push(this.eventInfoDto);
    }
    // - 删除信息来源
    public deleteInfoFrom(index: number) {
        this.eventInfoDtos.splice(index, 1);
    }
    // 确定--添加信息来源
    public addEventInfoFrom() {
        this.$refs.eventInfoFrom.validate(async (valid: boolean) => {
            if (valid) {
                this.$set(this.eventInfoDtos, this.infoVolistIndex, this.eventInfoDto);
                this.infoFromDialog = false;
            }
        });
    }
    // 取消--添加信息来源
    public cancelAddInfoFrom() {
        this.infoFromDialog = false;
    }
    // 验证信息来源
    public validateInfoFrom(rule: object, value: string, callback: any) {
        const list: EventInfoDto[] = [];
        this.eventInfoDtos.map((item: EventInfoDto, index: number) => {
            if (item.infoFrom) {
                list.push(item);
            }
        });
        this.eventInfoDtos = list;
        if (list.length === 0) {
            this.eventBasicInfo.eventInfos = [{  // 信息来源列表
                eventId: 0,         //事件id
                infoFromUrl: '',         //信息来源媒体URL
                mediaType: 1,         //媒体类型 1新闻、2报告
                id: 0,         //null
                infoFrom: '',         //信息来源媒体
                happenTime: ''         //发生时间
            }];
            callback(new Error('请填写信息来源!'));
        }
        this.eventBasicInfo.eventInfos = this.eventInfoDtos;
        callback();
    }
    // 企业信息弹出框
    public openCompanyDetailDialog() {
        this.companyDetailDialog = true;
    }
    // 关闭企业信息弹出框
    public closeCompanyDialog() {
        this.companyDetailDialog = false;
    }
    // 获取企业名称
    public getName(company: {id: number, name: string}) {
        this.eventBasicInfo.companyId =  company.id;
        this.eventBasicInfo.companyName = company.name;
        this.companyText = company.name;
        this.companyId = company.id.toString();
        this.getCompanyInfo();
    }
    // 查看详情--跳转到企业详情页
    public toCompanyDetail() {
        this.$router.push({name: 'company-detail', params: {itemId: this.companyId}});
    }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
    .noPass {
        color: #f00;
    }
    .w-100 {
        width: 100%;
    }
    .w-50 {
        width: 50%;
    }
    .align-center-self {
        text-align: center;
        line-height: 40px;
    }
    .company-detail {
        width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    .cmsInfoUrl {
        color: #409EFF;
        text-align: center;
        text-decoration: underline;
        display: inline-block;
        width: 50%;
        height: 30px;
    }
    .minheight{
        height: 100px;
        overflow-y: auto;
        padding: 0 10px;
        border-radius: 5px;
    }
</style>
